﻿package com.morefuntek.mail;

import java.util.Date;

public class SendEmail {
	private static String To1 = "ywhpp@qq.com";

	public static void sendEmail(String port) {

		Body body = new Body();
		body.appendWrapLine(1);
		body.appendTab(1);
		body.append("端口" + port + ":出现异常，在5分钟后仍然未能收到消息，请检查！");
		body.appendWrapLine(3);
		body.appendTab(1);
		body.append("致");
		body.append("礼！");
		body.appendWrapLine(3);
		body.appendTab(4);
		body.append("杨助志");
		body.appendWrapLine(1);
		body.appendTab(4);
		body.append(new Date());

		Mail mail = new Mail();
		mail.setSmtpServer("www.morefuntek.com");
		mail.setFrom("zhuzhi.yang@morefuntek.com");
		mail.setAuthUser("zhuzhi.yang@morefuntek.com");
		mail.setAuthPassword("123456.mf");
		mail.setSubject("短信猫异常报警");
		mail.setBody(body);
		mail.setTo(To1);
		// mail.addCopyTo(CopyTo);
		reSendWhileFailed(mail);

	}

	private static void reSendWhileFailed(final Mail mail) {
		for (int i = 0; !MailSender.send(mail) && i < 3; i++) {
			try {
				Thread.sleep(60 * 1000);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}

	public static void main(String[] args) {
		SendEmail.sendEmail("com22");
	}

}
